package com.ganzalang.gmall.concurrentart.jvm;

import lombok.SneakyThrows;

import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: Ganzalang
 * @Date 2022/4/19 17:45
 */
public class VarVisibility {

    private volatile static boolean initFlag = false;


    public static void main(String[] args) throws InterruptedException {
       new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("initializing data...");

                while (!initFlag) {
                }

                System.out.println("Success...");
            }
        }).start();

       Thread.sleep(2000);

       new Thread(new Runnable() {
           @Override
           public void run() {
               change();
           }
       }).start();

    }

    public static void change() {
        initFlag = true;
    }
}
